import requests
from lxml.html import etree

if __name__ == '__main__':
    url = 'http://pic.netbian.com/e/search/result/?searchid=2549'
    headers = {
        "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Mobile Safari/537.36"
    }
    page_text = requests.get(url=url, headers=headers).text
    tree = etree.HTML(page_text)

    li_list = tree.xpath('//div[@class="slist"]/ul/li')

    for li in li_list:
        new_url = 'http://pic.netbian.com/' + li.xpath('./a/img/@src')[0]
        new_name = new_url.split('/')[-1]
        img_data = requests.get(url=new_url, headers=headers).content
        img_path = '../images/' + new_name
        with open(img_path, 'wb') as fp:
            fp.write(img_data)
            print(new_name, "下载成功！！！")
